<template>
  <div>
    <el-table
      :data="toplist"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="title" label="名称" sortable width="180">
      </el-table-column>
      <el-table-column label="图标" sortable width="180">
        <template slot-scope="scope">
          <i :class="scope.row.icon"></i>
        </template>
      </el-table-column>
      <el-table-column label="类型" sortable width="180">
        <template slot-scope="scope">
          <el-button
            :type="scope.row.type == 1 ? 'primary' : 'success'"
            plain
            >{{ scope.row.type == 1 ? "目录" : "菜单" }}</el-button
          >
        </template>
      </el-table-column>
      <el-table-column prop="url" label="地址"> </el-table-column>
      <el-table-column label="操作" sortable width="180">
        <template slot-scope="scope">
          <el-button type="warning" @click="edit(scope.row)">编辑</el-button>
          <el-button type="danger" @click="remake(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  props: ["toplist"],
  data() {
    return {};
  },
  computed: {},
  created() {},
  mounted() {},
  watch: {},
  methods: {
    edit(obj) {
      // 编辑
      this.$emit("edit", obj);
    },
    remake(obj) {
      // 删除
      this.$confirm("确认删除？")
        .then((_) => {
          this.$api.postmenudelete({ id: obj.id }).then((res) => {
            this.$message({
              message: "恭喜你删除成功",
              type: "success",
            });
            this.$emit('updataPages')
          });
        })
        .catch((_) => {
          this.$message.error('已取消');
        });
    },
  },
  components: {},
};
</script>

<style scoped lang="scss">
</style>
